package webgamemaker.Editor;

import webgamemaker.Common.Callback;
import webgamemaker.Common.GameMap;
import webgamemaker.Common.MapData;
import webgamemaker.Common.TileData;

import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.VLayout;

public class BaseTileCombiner extends VLayout 
{
	public TileSetEditor father;
	public GameMap container;
	
	public BaseTileCombiner(final TileSetEditor father)
	{
		container = new GameMap(new MapData(1,1,1));
		container.grid = true;
		final Button addButton = new Button("add to tileset");
		addButton.setDisabled(true);
		setMembers(container, addButton);
		
		ProjectManager.getInstance().tilesetPanel.addSelectCallback(new Callback()
		{
			public void onCall(Object src) 
			{
				TileSetPicker tilesetPicker = (TileSetPicker)src;
				container.cursorWidth = tilesetPicker.selectX2-tilesetPicker.selectX1+1;
				container.cursorHeight = tilesetPicker.selectY2-tilesetPicker.selectY1+1;
			}
		});
		
		container.addSelectCallback(new Callback()
			{
				public void onCall(Object src) 
				{
					TileSetPicker tilesetPicker = ProjectManager.getInstance().tilesetPanel.selectedTileSetPicker;
					container.mapData.tiles[0][0] = tilesetPicker.tileset.tiles.get(tilesetPicker.selectX1+tilesetPicker.selectY1*tilesetPicker.nbTilePerLine);
					container.redraw();
					addButton.setDisabled(false);
				}
			});
		
		addButton.addClickHandler(new ClickHandler()
			{
				public void onClick(ClickEvent event) 
				{
					father.tileset.tiles.add(container.mapData.tiles[0][0].clone());
					father.updateTileSetPicker();
				}
			});
	}
}
